package com.itheima.api.array.demo02;

public class BubbleSort {

    public static void main(String[] args) {

        int[] arr = {12, 54, 31, 42, 89, 26, 55, 60};

        printArr(arr);

        System.out.println();

        bubbleSort(arr);

        printArr(arr);

    }

    public static void bubbleSort(int[] arr) {

        for (int y = 0; y < arr.length - 1; y++) {
            for (int x = 0; x < arr.length - 1 - y; x++) {

                if (arr[x] > arr[x + 1]) {
                    int temp = arr[x];
                    arr[x] = arr[x + 1];
                    arr[x + 1] = temp;
                }
            }

        }

    }

    public static void printArr(int[] arr) {

        for(int a : arr){
            System.out.print(a + " ");
        }

    }

}
